
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Mr Bao
 */
public class HomeMain extends List implements CommandListener {

    private HomeScreen homeScreen;
    private Command cmdExit;

    public HomeMain(HomeScreen homeScreen) {
        super("UpAnh", List.IMPLICIT);
        this.homeScreen = homeScreen;
        append("View Image", null);
        append("Upload Image", null);
        if (Common.UserId <= 0) {
            append("Dang nhap", null);
            append("Dang ky", null);
        }
        cmdExit = new Command("Exit", Command.EXIT, 2);
        this.addCommand(cmdExit);
        this.setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdExit) {
            Common.Client.Exit();
            homeScreen.destroyApp(true);
        } else if (c == this.SELECT_COMMAND) {
            switch (getSelectedIndex()) {
                case 0:
                    if (Common.UserId <= 0) {
                        homeScreen.DisplayError(ErrorType.NotLogin);
                    } else {
                        homeScreen.DisplayChoseViewAlbumForm();
                    }
                    break;
                case 1:
                    if (Common.UserId <= 0) {
                        homeScreen.DisplayError(ErrorType.NotLogin);
                    } else {
                        homeScreen.DisplayAlbumForm();
                    }
                    break;
                case 2:
                    homeScreen.DisplayLoginForm();
                    break;
                case 3:
                    homeScreen.DisplayRegisterForm();
                    break;
                default:
                    break;
            }
        }
    }
}
